package com.sczmgk.hotline_pzh.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.sczmgk.hotline_pzh.R;
import com.sczmgk.hotline_pzh.utils.CommonUtils;
import com.sczmgk.hotline_pzh.utils.MyLog;

/**
 * 生成DiaLog的工厂类
 *
 * @author
 */
public class DialogFactory {
    private static final String TAG = DialogFactory.class.getSimpleName();

    /**
     * 取得进度打的DiaLog
     *
     * @param context
     * @param tip
     * @return
     */
    public static Dialog getProgressDislog(final Context context, String tip) {

        final Dialog dialog = new Dialog(context, R.style.style_progress_dialog);
        dialog.setContentView(R.layout.dialog_layout);
        // dialog.setCancelable(true);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        int width = CommonUtils.getScreenWidth(context);
        lp.width = (int) (0.6 * width);

        TextView titleTxtv = (TextView) dialog.findViewById(R.id.tvLoad);
        if (tip == null || tip.length() == 0) {
            titleTxtv.setText(R.string.dialog_default_text);
        } else {
            titleTxtv.setText(tip);
        }

        return dialog;
    }

//	/**
//	 * 生成正在加载的Dialog
//	 * 
//	 * @param context
//	 * @param tip
//	 *            提示内容
//	 */
//	public static Dialog getLoadingDialog(Context context, String tip) {
//		Dialog loadingDialog = new Dialog(context, R.style.style_progress_dialog);
//		loadingDialog.setContentView(R.layout.dialog_loading_layout);
//		loadingDialog.setCancelable(true);
//		Window window = loadingDialog.getWindow();
//		WindowManager.LayoutParams lp = window.getAttributes();
//		int width = CommonUtils.getScreenWidth(context);
//		lp.width = (int) (0.5 * width);
//		TextView titleTxtv = (TextView) loadingDialog.findViewById(R.id.tvLoad);
//		loadingDialog.setCanceledOnTouchOutside(false);
//		if (tip == null || tip.length() == 0) {
//			titleTxtv.setText(R.string.dialog_default_text);
//		} else {
//			titleTxtv.setText(tip);
//		}
//		return loadingDialog;
//	}

    /**
     * 生成正在加载的Dialog
     *
     * @param context
     * @param resId   提示内容引用
     */
    public static Dialog getLoadingDialog(final Context context, int resId) {
        Dialog loadingDialog = new Dialog(context, R.style.style_progress_dialog);
//		loadingDialog.setContentView(R.layout.dialog_loading_layout);
        loadingDialog.setContentView(R.layout.dialog_loading_layout_next);

        loadingDialog.setCancelable(true);
        Window window = loadingDialog.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        int width = CommonUtils.getScreenWidth(context);
        lp.width = (int) (0.15 * width);//设置dialog的宽度
        lp.height = (int) (0.15 * width);//设置dialog的高度
//		TextView titleTxtv = (TextView) loadingDialog.findViewById(R.id.tv_loading);
        loadingDialog.setCanceledOnTouchOutside(false);
//		String tip = context.getResources().getString(resId);
//		if (tip != null) {
//			titleTxtv.setText(tip);
//		}
        return loadingDialog;
    }

    /**
     * 生成正在加载的Dialog
     *
     * @param context 提示内容引用
     */
    public static Dialog getLoadingDialog(final Context context) {
        Dialog loadingDialog = new Dialog(context, R.style.style_progress_dialog);
        loadingDialog.setContentView(R.layout.dialog_loading_layout_next);
        ImageView ivLoading = (ImageView) loadingDialog.findViewById(R.id.iv_loading_anim);
        AnimationDrawable ad = (AnimationDrawable) ivLoading.getBackground();
        ad.start();
        loadingDialog.setCancelable(true);
        Window window = loadingDialog.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        int width = CommonUtils.getScreenWidth(context);
        lp.width = (int) (0.15 * width);//设置dialog的宽度
        lp.height = (int) (0.15 * width);//设置dialog的高度
        loadingDialog.setCanceledOnTouchOutside(false);
        return loadingDialog;
    }

    /**
     * 生成正在加载的Dialog
     *
     * @param context
     * @param resId   提示内容引用
     */
    public static Dialog getHelpDialog(final Context context, int resId, int x, int y, int w, int h) {
        final Dialog loadingDialog = new Dialog(context, R.style.style_progress_dialog);
        loadingDialog.setContentView(R.layout.dialog_help);
        View viewById = loadingDialog.findViewById(R.id.rl_novoice_container);
        viewById.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (loadingDialog.isShowing()) {

                    loadingDialog.dismiss();
                }
            }
        });
        loadingDialog.setCancelable(true);
        Window window = loadingDialog.getWindow();
        window.setGravity(Gravity.LEFT | Gravity.TOP);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = w;//设置dialog的宽度
        lp.height = h;//设置dialog的高度
        lp.x = x;
        lp.y = y;
        ImageView imageView = (ImageView) loadingDialog.findViewById(R.id.iv_help_hint);
        loadingDialog.setCanceledOnTouchOutside(true);
        if (resId != 0) {
            imageView.setBackgroundResource(resId);
        }
        return loadingDialog;
    }

    /**
     * 显示确认的对话框
     *
     * @param ctx
     * @param neutralListener
     * @param negativeListener
     * @param message
     * @param neutralText
     * @param negativeText
     */
    public static void showConfirmDialog(Context ctx,
                                         OnClickListener neutralListener, OnClickListener negativeListener,
                                         String message, String neutralText, String negativeText) {
        MessageDialog msgDialog = new MessageDialog(ctx, true);

        msgDialog.setMessage(message);
        msgDialog.setBtn1ClickListener(neutralListener);
        msgDialog.setBtn1Text(neutralText);

        msgDialog.setBtn2ClickListener(negativeListener);
        msgDialog.setBtn2Text(negativeText);

        msgDialog.setBtn3Visible(false);

        msgDialog.setBtn4Visible(false);

        msgDialog.show();

    }

    /**
     * 显示内容的对话框
     *
     * @param ctx
     * @param neutralListener
     * @param negativeListener
     * @param message
     * @param neutralText
     * @param negativeText
     * @return
     */
    public static Dialog showContentDialog(Context ctx,
                                           OnClickListener neutralListener, OnClickListener negativeListener,
                                           String message, String neutralText, String negativeText) {
        MessageDialog msgDialog = new MessageDialog(ctx, true);

        msgDialog.setMessage(message);
        msgDialog.setBtn1ClickListener(neutralListener);
        msgDialog.setBtn1Text(neutralText);

        msgDialog.setBtn2ClickListener(negativeListener);
        msgDialog.setBtn2Text(negativeText);

        msgDialog.setBtn3Visible(false);

        msgDialog.setBtn4Visible(false);

        msgDialog.show();

        return msgDialog;
    }

    /******************* 只有确定的Dialog *************************/


    /**
     * @param context      上下文
     * @param title
     * @param message      提示信息
     * @param sureString   确定按钮文字
     * @param surelistener 确定按钮监听事件
     */
    public static void warningDialog(Context context, String title, String message,
                                     String sureString, OnClickListener surelistener) {
        if (null == context) {
            return;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setTitle(title);
        msgDialog.setTitleTextColor(context.getResources().getColor(R.color.common_title_color));
        msgDialog.setOneBtnStyle();
        msgDialog.setBtn4Enable(true);
        msgDialog.setMessage(message);
        msgDialog.setBtn4Text(sureString);
        msgDialog.setOneBtnClickListener(surelistener);
        if (!TextUtils.isEmpty(sureString)) {
            msgDialog.setBtn4Text(sureString);
        }
        msgDialog.show();
    }


    /**
     * @param context
     *            上下文
     * @param str
     *            提示信息
     * @param sureString
     *            确定按钮文字
     * @param surelistener
     *            确定按钮监听事件
     */
//	public static MessageDialog warningDialog(Context context, String str,
//			String sureString, OnClickListener surelistener) {
//		if (null == context) {
//			return null;
//		}
//		if (context instanceof Activity) {
//			Activity activity = (Activity) context;
//			if (activity.isFinishing()) {
//				return null;
//			}
//		}
//		MessageDialog msgDialog = new MessageDialog(context);
//		msgDialog.setOneBtnStyle();
//		msgDialog.setMessage(str);
//		msgDialog.setBtn4Text(sureString);
//		msgDialog.setBtn4ClickListener(surelistener);
//		msgDialog.show();
//		return msgDialog;
//	}

    /**
     * @param context
     * @param str
     * @return
     */
    public static MessageDialog warningDialog(Context context, String str) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setOneBtnStyle();
        msgDialog.setMessage(str);
        msgDialog.show();
        return msgDialog;
    }

    /**
     * @param context
     * @param id
     */
    public static MessageDialog warningDialog(Context context, int id) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setOneBtnStyle();
        msgDialog.setMessage(context.getResources().getString(id));
        msgDialog.show();
        return msgDialog;
    }

    /**
     * @param context      上下文
     * @param str          提示信息
     * @param sureString   确定按钮文字
     * @param surelistener 确定按钮监听事件
     */
    public static MessageDialog warningDialog(Context context, String str,
                                              String sureString, OnClickListener surelistener, boolean Cancelable) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setOneBtnStyle();
        msgDialog.setCancelable(Cancelable);
        msgDialog.setMessage(str);
        msgDialog.setBtn4Text(sureString);
        msgDialog.setBtn4ClickListener(surelistener);
        msgDialog.show();
        return msgDialog;
    }

    /**
     * @param context      上下文
     * @param strId        提示信息
     * @param sureString   确定按钮文字
     * @param surelistener 确定按钮监听事件
     */
    public static MessageDialog warningDialog(Context context, int strId,
                                              String sureString, OnClickListener surelistener) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            MyLog.d(TAG, "context " + activity.getClass().getSimpleName()
                    + " isFinishing=" + activity.isFinishing() + "activity"
                    + activity);
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setOneBtnStyle();
        msgDialog.setMessage(context.getResources().getString(strId));
        if (!TextUtils.isEmpty(sureString)) {
            msgDialog.setBtn4Text(sureString);
        }
        msgDialog.setBtn4ClickListener(surelistener);
        msgDialog.show();
        return msgDialog;
    }

    /**
     * @param context      上下文
     * @param strId        提示信息
     * @param sureString   确定按钮文字
     * @param surelistener 确定按钮监听事件
     */
    public static MessageDialog warningDialogs(Context context, int strId,
                                               String sureString, OnClickListener surelistener) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            MyLog.d(TAG, "context " + activity.getClass().getSimpleName()
                    + " isFinishing=" + activity.isFinishing() + "activity"
                    + activity);
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setOneBtnStyle();
        msgDialog.setMessage(context.getResources().getString(strId));
        if (!TextUtils.isEmpty(sureString)) {
            msgDialog.setBtn4Text(sureString);
        }
        msgDialog.setBtn4ClickListener(surelistener);
        msgDialog.show();
        return msgDialog;
    }

    /**
     * @param context      上下文
     * @param strId        提示信息
     * @param sureStringId 确定按钮文字
     * @param surelistener 确定按钮监听事件
     */
    public static MessageDialog warningDialog(Context context, int strId,
                                              int sureStringId, OnClickListener surelistener) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setOneBtnStyle();
        msgDialog.setMessage(context.getResources().getString(strId));
        msgDialog.setBtn4Text(sureStringId);
        msgDialog.setBtn4ClickListener(surelistener);
        msgDialog.show();
        return msgDialog;
    }

    /**
     * @param context      上下文
     * @param str          提示信息
     * @param sureStringId 确定按钮文字
     * @param surelistener 确定按钮监听事件
     */
    public static MessageDialog warningDialog(Context context, String str,
                                              int sureStringId, OnClickListener surelistener) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setOneBtnStyle();
        msgDialog.setMessage(str);
        msgDialog.setBtn4Text(sureStringId);
        msgDialog.setBtn4ClickListener(surelistener);
        msgDialog.show();
        return msgDialog;
    }

    /******************* 取消和确定的Dialog *************************/


    /**
     * 选择对话框
     *
     * @param context      上下文
     * @param message      提示信息
     * @param sureString   确定按钮文字
     * @param surelistener 确定按钮监听事件
     */
    public static MessageDialog chooseDialog(Context context, String message, String sureString, OnClickListener surelistener) {

        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(message);
        msgDialog.setBtn2ClickListener(surelistener);
        if (!TextUtils.isEmpty(sureString)) {
            msgDialog.setBtn2Text(sureString);
        }
        msgDialog.show();
        return msgDialog ;
    }

    /**
     * 选择对话框
     *
     * @param context      上下文
     * @param message      提示信息
     * @param sureStringId 确定按钮文字
     * @param surelistener 确定按钮监听事件
     */
    public static void chooseDialog(Context context, String message,
                                    int sureStringId, OnClickListener surelistener) {
        if (null == context) {
            return;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(message);
        msgDialog.setBtn2ClickListener(surelistener);
        if (!TextUtils.isEmpty(String.valueOf(sureStringId))) {
            msgDialog.setBtn2Text(sureStringId);
        }
        msgDialog.show();
    }

    /**
     * 选择性别的DiaLog
     *
     * @param context
     * @param layoutId
     * @param title
     */
    public static MessageDialog selectSexDialog(Context context, int layoutId, String sax, String title, MessageDialog.OnSexChangedListener saxChangedListener) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context, layoutId, saxChangedListener, sax);
        msgDialog.setTitleTextColor(context.getResources().getColor(R.color.common_title_color));
        msgDialog.setTitle(title);
        msgDialog.setTitleGravity(Gravity.LEFT);
        msgDialog.setBtnContentGone();
        msgDialog.setBtnTopLineVisibility(View.GONE);
        msgDialog.show();
        return msgDialog;
    }

    /**
     * 选择对话框
     *
     * @param context
     * @param message
     * @param sureStringId   确定按钮文字
     * @param surelistener   确定按钮监听事件
     * @param cancellistener 关闭的监听事件
     * @param Cancelable
     */
    public static void chooseDialog(Context context, String message,
                                    int sureStringId, OnClickListener surelistener,
                                    OnClickListener cancellistener, boolean Cancelable) {
        if (null == context) {
            return;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setCancelable(Cancelable);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(message);
        msgDialog.setBtn1ClickListener(cancellistener);
        msgDialog.setBtn2ClickListener(surelistener);
        if (!TextUtils.isEmpty(String.valueOf(sureStringId))) {
            msgDialog.setBtn2Text(sureStringId);
        }
        msgDialog.show();
    }

    /**
     * 带EditText Dialog
     *
     * @param context
     * @param message        提示信息
     * @param sureString     确定按钮文字
     * @param cancelString   关闭按钮的文字
     * @param surelistener   确定按钮监听事件
     * @param cancellistener 退出按钮监听事件
     * @param Cancelable
     */
    public static void chooseDialog(Context context, String message,
                                    String sureString, String cancelString,
                                    OnClickListener surelistener, OnClickListener cancellistener,
                                    boolean Cancelable) {
        if (null == context) {
            return;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setCancelable(Cancelable);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(message);
        msgDialog.setBtn1ClickListener(cancellistener);
        msgDialog.setBtn2ClickListener(surelistener);
        msgDialog.setBtn1Text(cancelString);
        msgDialog.setBtn2Text(sureString);
        msgDialog.show();
    }

    /**
     * 生成选择对话框
     *
     * @param context
     * @param message        提示信息
     * @param sureResID      确定按钮的文字
     * @param cancelResId    关闭按钮的文字
     * @param surelistener   确定按钮监听事件
     * @param cancellistener 退出按钮监听事件
     * @return
     */
    public static MessageDialog chooseDialog(Context context, String message,
                                             int sureResID, int cancelResId,
                                             OnClickListener surelistener, OnClickListener cancellistener) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(message);
        msgDialog.setBtn1ClickListener(cancellistener);
        msgDialog.setBtn2ClickListener(surelistener);
        msgDialog.setBtn1Text(context.getResources().getString(cancelResId));
        msgDialog.setBtn2Text(context.getResources().getString(sureResID));
        return msgDialog;
    }

    /**
     * 生成选择对话框
     *
     * @param context
     * @param message        提示信息
     * @param sureString     确定按钮的文字
     * @param cancelString   关闭按钮的文字
     * @param surelistener   确定按钮监听事件
     * @param cancellistener 退出按钮监听事件
     * @return
     */
    public static MessageDialog chooseDialog(Context context, String message,
                                             String sureString, String cancelString,
                                             OnClickListener surelistener, OnClickListener cancellistener) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(message);
        msgDialog.setBtn1ClickListener(cancellistener);
        msgDialog.setBtn2ClickListener(surelistener);
        msgDialog.setBtn1Text(cancelString);
        msgDialog.setBtn2Text(sureString);
        return msgDialog;
    }

    /**
     * 生成选择对话框
     *
     * @param context      上下文
     * @param message      提示信息
     * @param sureString   确定按钮文字
     * @param surelistener 确定按钮监听事件
     * @param Cancelable
     */
    public static void chooseDialog(Context context, String message,
                                    String sureString, OnClickListener surelistener, boolean Cancelable) {
        if (null == context) {
            return;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setCancelable(Cancelable);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(message);
        msgDialog.setBtn2ClickListener(surelistener);
        msgDialog.setBtn2Text(sureString);
        msgDialog.show();
    }

    /**
     * 生成选择对话框
     *
     * @param context      上下文
     * @param messageId    提示信息
     * @param sureStringId 确定按钮文字
     * @param surelistener 确定按钮监听事件
     */
    public static void chooseDialog(Context context, int messageId,
                                    int sureStringId, OnClickListener surelistener) {
        if (null == context) {
            return;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(context.getResources().getString(messageId));
        msgDialog.setBtn2ClickListener(surelistener);
        if (!TextUtils.isEmpty(String.valueOf(sureStringId))) {
            msgDialog.setBtn2Text(sureStringId);
        }
        msgDialog.show();
    }

    /**
     * 生成选择对话框
     *
     * @param context      上下文
     * @param messageId    提示信息
     * @param sureString   确定按钮文字
     * @param surelistener 确定按钮监听事件
     */
    public static void chooseDialog(Context context, int messageId,
                                    String sureString, OnClickListener surelistener) {
        if (null == context) {
            return;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(context.getResources().getString(messageId));
        msgDialog.setBtn2ClickListener(surelistener);
        if (!TextUtils.isEmpty(sureString)) {
            msgDialog.setBtn2Text(sureString);
        }
        msgDialog.show();
    }

    /**
     * @param context
     * @param messageId
     * @param sureString
     * @param surelistener
     * @param title
     * @return
     */
    public static MessageDialog editDiaglog(Context context, int messageId,
                                            String sureString, OnClickListener surelistener, int title) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setEditTextVisible(true);
        msgDialog.setEditPassword(true);
        msgDialog.setTitle(context.getResources().getString(title));
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(context.getResources().getString(messageId));
        msgDialog.setBtn2ClickListener(surelistener);
        if (!TextUtils.isEmpty(sureString)) {
            msgDialog.setBtn2Text(sureString);
        }
        msgDialog.show();
        return msgDialog;
    }

    /**
     * 带EditText Dialog
     *
     * @param context
     * @param messageId    提示内容
     * @param sureString   按钮内容
     * @param surelistener 按钮事件
     * @param title        标题
     * @param isPassword   EditText是否为密码
     * @return
     */
    public static MessageDialog editDiaglog(Context context, int messageId,
                                            String sureString, OnClickListener surelistener, int title,
                                            boolean isPassword) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setEditTextVisible(true);
        if (isPassword) {
            msgDialog.setEditPassword(true);
        } else {
            msgDialog.setEditPassword(false);
        }
        msgDialog.setTitle(context.getResources().getString(title));
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(context.getResources().getString(messageId));
        msgDialog.setBtn2ClickListener(surelistener);
        if (!TextUtils.isEmpty(sureString)) {
            msgDialog.setBtn2Text(sureString);
        }
        msgDialog.show();
        return msgDialog;
    }

    /**
     * 带EditText Dialog
     *
     * @param context
     * @param message      提示内容
     * @param sureString   按钮内容
     * @param surelistener 按钮事件
     * @param title        标题
     * @param isPassword   EditText是否为密码
     * @return
     */
    public static MessageDialog editDiaglog(Context context, String message,
                                            String sureString, OnClickListener surelistener, String title,
                                            boolean isPassword) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setEditTextVisible(true);
        if (isPassword) {
            msgDialog.setEditPassword(true);
        } else {
            msgDialog.setEditPassword(false);
        }
        msgDialog.setTitle(title);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(message);
        msgDialog.setBtn2ClickListener(surelistener);
        if (!TextUtils.isEmpty(sureString)) {
            msgDialog.setBtn2Text(sureString);
        }
        msgDialog.show();
        return msgDialog;
    }

    /**
     * 带EditText Dialog
     *
     * @param context
     * @param message      提示内容
     * @param sureString   按钮内容
     * @param surelistener 按钮事件
     * @param title        标题
     * @param isPassword   EditText是否为密码
     * @param length
     * @return
     */
    public static MessageDialog editDiaglog(Context context, String message,
                                            String sureString, OnClickListener surelistener, String title,
                                            boolean isPassword, int length) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setEditTextVisible(true);
        if (isPassword) {
            msgDialog.setEditPassword(true);
        } else {
            msgDialog.setEditPassword(false);
        }
        msgDialog.setTitle(title);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(message);
        msgDialog.setEditTextLength(length);
        msgDialog.setBtn2ClickListener(surelistener);
        if (!TextUtils.isEmpty(sureString)) {
            msgDialog.setBtn2Text(sureString);
        }
        msgDialog.show();
        return msgDialog;
    }

    /**
     * 生成警告对话框
     *
     * @param context      上下文
     * @param strId        提示信息
     * @param sureStringId 确定按钮文字
     * @param surelistener 确定按钮监听事件
     * @param title        标题
     */

    public static MessageDialog warningDialog(Context context, int strId,
                                              int sureStringId, OnClickListener surelistener, int title) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setOneBtnStyle();
        msgDialog.setTitle(context.getResources().getString(title));
        msgDialog.setMessage(context.getResources().getString(strId));
        msgDialog.setBtn4Text(sureStringId);
        msgDialog.setBtn4ClickListener(surelistener);
        msgDialog.show();
        return msgDialog;
    }

    /**
     * 生成警告对话框
     *
     * @param context      上下文
     * @param string       提示信息
     * @param sureStringId 确定按钮文字
     * @param surelistener 确定按钮监听事件
     * @param title        标题
     */
    public static MessageDialog warningDialog(Context context, String string,
                                              int sureStringId, OnClickListener surelistener, int title) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setOneBtnStyle();
        msgDialog.setTitle(context.getResources().getString(title));
        msgDialog.setMessage(string);
        msgDialog.setBtn4Text(sureStringId);
        msgDialog.setBtn4ClickListener(surelistener);
        msgDialog.show();
        return msgDialog;
    }

    /**
     * 关闭对话框
     *
     * @param dialog
     */
    public static void dismissLoadingDialog(Dialog dialog) {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    /**
     * 显示DiaLog
     *
     * @param dialog
     */
    public static void showDialog(Dialog dialog) {
        if (dialog != null) {
            dialog.show();
        }
    }

    /**
     * 带EditText Dialog(测试用)
     *
     * @param context
     * @param message        提示内容
     * @param sureString     按钮内容
     * @param surelistener   按钮事件
     * @param title          标题
     * @param editTextContnt 编辑内容
     * @return
     */
    public static MessageDialog editDiaglog(Context context, int message,
                                            String sureString, OnClickListener surelistener, int title,
                                            int editTextContnt) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setEditTextVisible(true);
        msgDialog.setEditPassword(false);
        msgDialog.getEditText().setText(
                context.getResources().getString(editTextContnt));
        msgDialog.setTitle(context.getResources().getString(title));
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(context.getResources().getString(message));
        msgDialog.setBtn2ClickListener(surelistener);
        if (!TextUtils.isEmpty(sureString)) {
            msgDialog.setBtn2Text(sureString);
        }
        msgDialog.show();
        return msgDialog;
    }

    /**
     * 带EditText Dialog(测试用)
     *
     * @param context
     * @param message        提示内容
     * @param sureString     按钮内容
     * @param surelistener   按钮事件
     * @param title          标题
     * @param isPassword     EditText是否为密码
     * @param editTextContnt 编辑内容
     * @return
     */
    public static MessageDialog editDiaglog(Context context, String message,
                                            String sureString, OnClickListener surelistener, String title,
                                            boolean isPassword, int length, int editTextContnt) {
        if (null == context) {
            return null;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing()) {
                return null;
            }
        }
        MessageDialog msgDialog = new MessageDialog(context);
        msgDialog.setEditTextVisible(true);
        if (isPassword) {
            msgDialog.setEditPassword(true);
        } else {
            msgDialog.setEditPassword(false);
        }
        msgDialog.setTitle(title);
        msgDialog.setTwoBtnStyle();
        msgDialog.setMessage(message);
        msgDialog.getEditText().setContentDescription(
                (context.getResources().getString(editTextContnt)));
        msgDialog.setEditTextLength(length);
        msgDialog.setBtn2ClickListener(surelistener);
        if (!TextUtils.isEmpty(sureString)) {
            msgDialog.setBtn2Text(sureString);
        }
        msgDialog.show();
        return msgDialog;
    }
}
